// pages/giftReceived/giftReceived.js
import giftApi from "../../service/giftApi";
const app = getApp()
const SUCCESS_CODE = app.globalData.codeConfig.errCode.SUCCESS_CODE
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getGiftData: {},
    giftId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      giftId: options.giftId
    })
    console.log(this.data.giftId, '收到礼物giftId');
    this.getGiftInfo()
  },

  // 获取礼物信息
  getGiftInfo() {
      giftApi.getGiftInfo({giftId: this.data.giftId}).then(res => {
        if (res.data.errCode === SUCCESS_CODE) {
          this.setData({
            getGiftData: res.data.data
          })
        }
      })
  },

  // 查看商品详情
  onToGoodsDetail() {
    let goodsId = this.data.getGiftData.giftInfo.goodsId
    console.log(goodsId, 'goodsId');
    wx.navigateTo({
      url: `../goodsDetail/goodsDetail?goodsId=${goodsId}`
    })
  },

  // 查看礼物
  onLookGift(e) {
    wx.switchTab({
      url: `../couponBag/couponBag`
    })
  },

  // 立即提货
  onPickUpNow(e) {
    let goodsId = this.data.getGiftData.giftInfo.goodsId
    let goodsName = this.data.getGiftData.giftInfo.name
    let goodsCount = this.data.getGiftData.giftInfo.count
    let url = `../pickUpGoods/pickUpGoods?goodsId=${goodsId}&goodsName=${goodsName}&goodsCount=${goodsCount}`
    wx.navigateTo({
      url
    })
  }
})